using System;
using System.Management.Automation.Host;
using System.Threading;

namespace Fines.Powershell.PowershellMSBuildTask
{
    /// <summary>
    /// The host class.
    /// </summary>
    public class PowershellHost : PSHost
    {
        public PowershellHost( IPowershellTask task )
        {
            this.task = task;

            this.ui = new PowershellHostUI( task );
        }

        public override System.Globalization.CultureInfo CurrentCulture
        {
            get { return Thread.CurrentThread.CurrentCulture; }
        }

        public override System.Globalization.CultureInfo CurrentUICulture
        {
            get { return Thread.CurrentThread.CurrentUICulture; }
        }

        public override void EnterNestedPrompt()
        {
            throw new NotImplementedException();
        }

        public override void ExitNestedPrompt()
        {
            throw new NotImplementedException();
        }

        public override Guid InstanceId
        {
            get { return instanceGuid; }
        }

        public override string Name
        {
            get { return typeof(PowershellHost).Name; }
        }

        public override void NotifyBeginApplication()
        {
            // nothing
        }

        public override void NotifyEndApplication()
        {
            // nothing
        }

        public override void SetShouldExit( int exitCode )
        {
            this.task.ShouldExit = true;
            this.task.ExitCode = exitCode;
        }

        public override PSHostUserInterface UI
        {
            get { return this.ui; }
        }

        public override Version Version
        {
            get { return new Version(1,0,0,0); }
        }


        private readonly IPowershellTask task;
        private readonly PowershellHostUI ui;
        private static readonly Guid instanceGuid = Guid.NewGuid();
    }
}
